import os

from utils import fsutils, utils


# 获取 OCR 结果的文件路径
def get_ocr_result_path(filepath: str, file_type: str, append=None):
    # 文件名字
    if append is None:
        file_name = "ocr_" + file_type + "_result"
    else:
        file_name = "ocr_" + file_type + "_result_" + append
    # 获取用于存储原始 OCR 结果的父目录路径
    parent_dir = fsutils.get_cache_path_for_category(file_name)
    # 构建最终的原始 OCR 结果文件路径
    r_path = os.path.join(parent_dir, os.path.basename(filepath) + '.' + file_type)
    return r_path


# 整理一行的数据
def organize_line(line_cell_list: list):
    new_line_cell_list = []
    # 遍历每一个单元格
    for cell in line_cell_list:
        if len(cell) == 0:
            # 将单元格重新封装
            new_line_cell = ['', [None, None], [None, None], [None, None], [None, None]]
            # 将单元格添加到列表
            new_line_cell_list.append(new_line_cell)
            continue
        # 字符组合为单元格
        new_line_cell = utils.group_cell(cell)
        # 将单元格添加到列表
        new_line_cell_list.append(new_line_cell)

    return new_line_cell_list
